package dissertation.extensions.ejbmodule.control;

import com.intellij.framework.FrameworkTypeEx;
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.openapi.module.ModuleType;
import dissertation.services.ejbmodule.EJBModuleService;
import dissertation.services.ejbmodule.IEJBModuleService;
import org.jetbrains.annotations.NotNull;

public class EJBFrameworkSupportInModuleProvider extends FrameworkSupportInModuleProvider {
    private IEJBModuleService ejbModuleService;

    public EJBFrameworkSupportInModuleProvider() {
        ejbModuleService = new EJBModuleService();
    }

    @NotNull
    @Override
    public FrameworkTypeEx getFrameworkType() {
        return FrameworkTypeEx.EP_NAME.findExtension(EJBFrameworkType.class);
    }

    @Override
    public boolean isEnabledForModuleBuilder(@NotNull ModuleBuilder builder) {
        return super.isEnabledForModuleBuilder(builder) && !(builder instanceof EJBJavaModuleBuilder);
    }

    @NotNull
    @Override
    public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel frameworkSupportModel) {
        return new EJBFrameworkSupportInModuleConfigurable();
    }

    @Override
    public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) {
        return ejbModuleService.isAcceptableModuleType(moduleType);
    }
}
